package com.test.pic;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import com.badibadi.infos.Results;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.HttpFileUpTool;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.id;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.os.Message;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class PiliangUpPictureActivity extends Activity {
	public static final String TAG = "aaa";

	Button button;
	Button button1;
	Button button2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_piliang_up_picture);
		button = (Button) findViewById(R.id.button1);
		button1 = (Button) findViewById(R.id.button2);
		button2 = (Button) findViewById(R.id.button3);
		button.setOnClickListener(listener);
		button1.setOnClickListener(listener);
		button2.setOnClickListener(listener);
	}

	/**
	 * 按钮响应事件
	 */
	private View.OnClickListener listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			Button button = (Button) v;
			switch (button.getId()) {
			case R.id.button1:
				AjaxParams params = new AjaxParams();
				try {
					params.put("info_head", new File("/sdcard/test.png"));// "/storage/sdcard1/DCIM/Camera/IMG_20140723_231753.jpg")
					// params.put("info_head", new
					// File("/sdcard/1401418603014.png"));
					// params.put("info_head", new File("/sdcard/123.jpg"));
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					   
				}// "/storage/sdcard1/DCIM/Camera/IMG_20140723_231742.jpg"

				FinalHttp fh = new FinalHttp();
				fh.post(Constants.BadiUrl + "upload_img", params,
						new AjaxCallBack<Object>() {

							@Override
							public void onLoading(long count, long current) {
								// TODO Auto-generated method stub
								super.onLoading(count, current);

							}

							@Override
							public void onSuccess(Object t) {
								// TODO Auto-generated method stub
								Results results = Utils.checkResult_NNN(
										PiliangUpPictureActivity.this,
										(String) t);
							}
						});
				break;
			case R.id.button2:
				AjaxParams params2 = new AjaxParams();
				try {
					// params2.put("info_head", new
					// File("/sdcard/test.png"));//"/storage/sdcard1/DCIM/Camera/IMG_20140723_231753.jpg")
					params2.put("info_head", new File(
							"/sdcard/1401418603014.png"));
					// params2.put("info_head", new File("/sdcard/123.jpg"));
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					   
				}// "/storage/sdcard1/DCIM/Camera/IMG_20140723_231742.jpg"

				FinalHttp fh2 = new FinalHttp();
				fh2.post(Constants.BadiUrl + "upload_img", params2,
						new AjaxCallBack<Object>() {

							@Override
							public void onLoading(long count, long current) {
								// TODO Auto-generated method stub
								super.onLoading(count, current);

							}

							@Override
							public void onSuccess(Object t) {
								// TODO Auto-generated method stub
								Results results = Utils.checkResult_NNN(
										PiliangUpPictureActivity.this,
										(String) t);
							}
						});
				break;
			case R.id.button3:
				AjaxParams params3 = new AjaxParams();
				try {
					// params3.put("info_head", new
					// File("/sdcard/test.png"));//"/storage/sdcard1/DCIM/Camera/IMG_20140723_231753.jpg")
					// params3.put("info_head", new
					// File("/sdcard/1401418603014.png"));
					params3.put("info_head", new File("/sdcard/123.jpg"));
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					   
				}// "/storage/sdcard1/DCIM/Camera/IMG_20140723_231742.jpg"

				FinalHttp fh3 = new FinalHttp();
				fh3.post(Constants.BadiUrl + "upload_img", params3,
						new AjaxCallBack<Object>() {

							@Override
							public void onLoading(long count, long current) {
								// TODO Auto-generated method stub
								super.onLoading(count, current);

							}

							@Override
							public void onSuccess(Object t) {
								// TODO Auto-generated method stub
								Results results = Utils.checkResult_NNN(
										PiliangUpPictureActivity.this,
										(String) t);
							}
						});
				break;

			}

			// String actionUrl = Constants.BadiUrl+"upload_img";
			// Map<String, String> params = new HashMap<String, String>();
			// // params.put("title", "strParamValue");
			// // params.put("remark", "strParamValue");
			// // params.put("usemame", "strParamValue");
			// // params.put("usertel", "strParamValue");
			// // params.put("eventime", "strParamValue");
			// // params.put("evenaddress", "strParamValue");
			// // params.put("addtime", "strParamValue");
			// // params.put("edittime", "strParamValue");
			// // params.put("muploadid", "strParamValue");
			// Map<String, File> files = new HashMap<String, File>();
			// //upload_img()
			//
			//
			// files.put("0", new File("/sdcard/test.png"));
			// files.put("1", new File("/sdcard/1401418603014.png"));
			// files.put("2", new File("/sdcard/123.jpg"));
			// // files.put("6.png", new File("/sdcard/6.png"));
			// try {
			// HttpFileUpTool.post(actionUrl, params, files);
			//
			// } catch (IOException e) {
			//    
			// }
		}
	};

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.piliang_up_picture, menu);
//		return true;
//	}

}
